<?php

namespace App\Repositories\Impl;

use App\Models\ActivityForm;
use App\Repositories\Contracts\ActivityFormRepository;

class ActivityFormRepositoryImpl implements ActivityFormRepository
{
    public function paginate($perPage, $filter)
    {
        $result = ActivityForm::where($filter)->paginate($perPage);
        return $result;
    }

    public function find($id, $columns = ['*'])
    {
        return ActivityForm::find($id, $columns);
    }

    public function findByFilter($filter, $columns = ['*'])
    {
        return ActivityForm::where($filter)->first($columns);
    }

    public function findNumByActivityId($activityId)
    {
        return ActivityForm::where('activity_id', $activityId)->whereIn('audit_status', [0, 1])->count();
    }

    public function store($data)
    {
        return ActivityForm::create($data);
    }

    public function update($data, $id)
    {
        return ActivityForm::whereId($id)->updateOrCreate($data);
    }

    public function updateByFilter($data, $where)
    {
        return ActivityForm::where($where)->update($data);
    }

    public function delete($id)
    {
        return ActivityForm::whereId($id)->delete();
    }
}
